#cmake file for project zlib
#author:guyadong
#created:2016/06/23
############################################################################
cmake_minimum_required( VERSION 2.6 )
project( make_zlib)   
# 只用于MSVC下生成zlib库,gcc本身提供zlib的静态库，所以不需要
if(MSVC AND WIN32)
	set(CMAKE_BUILD_TYPE Release)
	MESSAGE( STATUS "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" )     
	# Detect whether compiler is 64-bit
	if(CMAKE_CL_64)
	  set(64BIT 1)
	  message(STATUS "64-bit build")
	else()
	  message(STATUS "32-bit build")
	endif()

	#关闭C4819警告
	add_definitions("/\"wd4819\"")		
	message(STATUS "optional:/wd\"4819\"")
	#关闭CRT_SECURE警告
	add_definitions(-D_CRT_SECURE_NO_WARNINGS)
	message(STATUS "optional:-D_CRT_SECURE_NO_WARNINGS")	
    # Use the static C library for all build types
    foreach(var 
    	CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
      	CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
      	CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
      	CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
      )
      if(${var} MATCHES "/MD")
        string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
      endif()
    endforeach()	

	if (64BIT)
		set ( zlib_install_folder  zlib-windows-vc-x86_64 )
	else()
		set ( zlib_install_folder  zlib-windows-vc-x86 )
	endif()    
	set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../${zlib_install_folder}" CACHE PATH
		"folder to install zlib (default: ../${zlib_install_folder})"
		FORCE)
	MESSAGE( STATUS "CMAKE_INSTALL_PREFIX =${CMAKE_INSTALL_PREFIX}" )   
	MESSAGE( STATUS "zlib folder adding" )   
	add_subdirectory( zlib-1.2.8 )
else()
	MESSAGE( STATUS "only use for WIN32/MSVC" )   
endif(MSVC AND WIN32)
